//
//  BlackTitleView.m
//  danpin
//
//  Created by Hongyu Zhang on 15/11/18.
//  Copyright © 2015年 chuangjia. All rights reserved.
//

#import "BlackTitleView.h"
#import "viewconfig.h"

@implementation BlackTitleView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        if(_titleBgView == nil)
        {
            _titleBgView=[[UIImageView alloc] initWithFrame:CGRectZero];
            _titleBgView.image = [UIImage imageNamed:@"jbc_bg.png"];
            _titleBgView.alpha =0.9;
            
            [self addSubview:_titleBgView];
        }
        
        
        _titleView = [[UILabel alloc]init];
        _titleView.font = FONT(13);
        _titleView.textColor = [UIColor whiteColor];
        _titleView.backgroundColor = [UIColor clearColor];
        _titleView.textAlignment = NSTextAlignmentLeft;
        _titleView.lineBreakMode =  NSLineBreakByTruncatingTail;

        [self addSubview:_titleView];
        
        
        
    }
    return self;
}

- (void)layoutSubviews
{

    
    [super layoutSubviews];
}

- (void)dealloc
{
    if(_titleBgView)
    {
        [_titleBgView removeFromSuperview];
        _titleBgView = nil;
    }
    
    if(_titleView)
    {
        [_titleView removeFromSuperview];
        _titleView = nil;
    }
}

- (void) setTitle:(NSString*) str
{
    _titleView.text = str;
    
    _titleBgView.frame = CGRectMake(0,
                                    0,
                                    self.bounds.size.width,
                                    self.bounds.size.height);
    
    
    _titleView.frame = CGRectMake(PHOTO_FRAME_WIDTH,
                                  self.bounds.size.height - 20,
                                  self.bounds.size.width - PHOTO_FRAME_WIDTH*2,
                                  15);

}

@end
